/**
 * 
 */
package com.alianzamedica.controllers.profile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.objectsearch.sqlsearch.ObjectSearch;
import org.objectsearch.web.tools.Converter;
import org.w3c.dom.Document;

import com.alianzamedica.businessobject.Doctor;
import com.alianzamedica.businessobject.Profile;
import com.alianzamedica.tools.Enviroment;

/**
 * @author RMarquez_Inf
 *
 */
public class ProfileDeleteAction extends Action{
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Enviroment env = Enviroment.getInstance();
		Document doc = env.getDocument();
		ObjectSearch search = new ObjectSearch(doc,
				"com.alianzamedica.connection.ConnectionImpl");
		Integer id = Converter.string2Integer(request.getParameter("id"));
		String mensaje = "";
		if (id != null) {
			Profile profile = new Profile();
			profile.setId(id);
			search.deleteObject(profile);
			mensaje = "El perfil se elimino correctamente";
		} else {
			mensaje = "No hay perfil para borrar";
		}
		String linkRetorno = "/admin/profile/list.do";
		request.setAttribute("mensaje", mensaje);
		request.setAttribute("linkRetorno", linkRetorno);

		return mapping.findForward("success");
	}
}
